package com.panda.pandawash.activity;

import android.content.Context;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;

import com.panda.pandawash.R;
import com.panda.pandawash.adapter.MyViewPagerAdapter;
import com.panda.pandawash.fragment.ReportDayFragment;
import com.panda.pandawash.fragment.ReportMonthFragment;
import com.panda.pandawash.fragment.ReportWeekFragment;
import com.panda.pandawash.fragment.ReportYearFragment;
import com.panda.pandawash.view.StatusBarCompat;

import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

/**
 * Created by gaowf on 2017/2/10.
 */

public class ReportFormActivity extends AppCompatActivity implements ReportDayFragment.OnFragmentInteractionListener,
        ReportMonthFragment.OnFragmentInteractionListener,ReportWeekFragment.OnFragmentInteractionListener,
        ReportYearFragment.OnFragmentInteractionListener{

    private Context context;

    @ViewInject(R.id.report_form_return)
    private ImageView backImageView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_report_form);
        x.view().inject(this);
        if(Build.VERSION.SDK_INT>= Build.VERSION_CODES.KITKAT) {
            StatusBarCompat.compat(this, getResources().getColor(R.color.colorPrimary));
        }
        context = getApplicationContext();

        initViewPager();


    }
    

    private void initViewPager(){
        ViewPager mViewPager = (ViewPager) findViewById(R.id.report_form_viewpager);
        MyViewPagerAdapter viewPagerAdapter = new MyViewPagerAdapter(getSupportFragmentManager());
        viewPagerAdapter.addFragment(ReportDayFragment.newInstance(),getResources().getString(R.string.day_report_fragment_title));//添加Fragment
        viewPagerAdapter.addFragment(ReportWeekFragment.newInstance(),getResources().getString(R.string.week_report_fragment_title));
        viewPagerAdapter.addFragment(ReportMonthFragment.newInstance(),getResources().getString(R.string.month_report_fragment_title));
        viewPagerAdapter.addFragment(ReportYearFragment.newInstance(),getResources().getString(R.string.year_report_fragment_title));
        mViewPager.setAdapter(viewPagerAdapter);//设置适配器

        TabLayout mTabLayout = (TabLayout) findViewById(R.id.tab_layout_report_form);
        mTabLayout.addTab(mTabLayout.newTab().setText(getResources().getString(R.string.day_report_fragment_title)));//给TabLayout添加Tab
        mTabLayout.addTab(mTabLayout.newTab().setText(getResources().getString(R.string.week_report_fragment_title)));
        mTabLayout.addTab(mTabLayout.newTab().setText(getResources().getString(R.string.month_report_fragment_title)));
        mTabLayout.addTab(mTabLayout.newTab().setText(getResources().getString(R.string.year_report_fragment_title)));
        mTabLayout.setupWithViewPager(mViewPager);

    }

    @Override
    public void onFragmentInteraction(Uri uri) {

    }


    @Event(R.id.report_form_return)
    private void excuteReturn(View v) {
        finish();
    }
}
